package com.stony.core.struts.action;

import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ajaxtags.helpers.AjaxXmlBuilder;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class AjaxUpdateSuccessHandler extends AjaxAction {

	public void doAjax(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
	}

	public String getXmlContent(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		AjaxXmlBuilder ajaxXmlBuilder = new AjaxXmlBuilder();

		ajaxXmlBuilder.addItem("success", "Y");

		Map successResults = (Map) request.getAttribute("successResults");

		if (successResults != null) {

			Iterator it = successResults.keySet().iterator();

			while (it.hasNext()) {
				String key = (String) it.next();
				ajaxXmlBuilder.addItemAsCData(key, successResults.get(key)
						.toString());
			}
		}

		return ajaxXmlBuilder.toString();

	}

}
